<template>
	<view class="signinPage" :show="showSignIn">
		<!-- 签到 -->
		<u-overlay :show="showSignIn">
			<view class="signInPanel" v-if="!isSign">
				<view class="signTitle">
					<u--image src="/static/community/6.png" shape="square" mode="aspectFill" width="524rpx"
						height="268rpx" bgColor="transparent"></u--image>
					<view class="title">每日签到</view>
				</view>
				<view class="signInfo">
					<view>
						<view class="info">该签到了</view>
						<view class="info">签到可以获取V积分哦</view>
					</view>
					<view class="signBtn" @click="doSignIn">签到</view>
				</view>
			</view>
			<view class="signInPanel" v-else>
				<view class="signTitle">
					<u--image src="/static/community/7.png" shape="square" mode="aspectFill" width="524rpx"
						height="268rpx" bgColor="transparent"></u--image>
					<view class="title">签到成功</view>
				</view>
				<view class="signInfo">
					<view>
						<view class="info">您现有<text class="integral-text">{{integral}}</text>积分</view>
						<!-- <view class="info">你已经连续签到{{signInfo.continuity}}天</view>
						<view class="info">本月已经签到了{{signInfo.bmonth}}天</view> -->
					</view>
					<view class="signBtn" @click="goSignDetail">查看积分</view>
				</view>
			</view>
			<view class="closeSignPanel" @click="showSignIn = false">
				<u--image src="/static/community/1.png" shape="square" mode="aspectFill" width="70rpx"
					height="70rpx" bgColor="transparent"></u--image>
			</view>
		</u-overlay>
	</view>
</template>

<script>
	export default {
		name:"signin",
		data() {
			return {
				userId: "",
				openId:"",
				showSignIn: false,
				signInfo: {
					continuity: 0,
					bmonth: 0
				},
				isSign: false,
				integral: ''
			};
		},
		created() {
			this.checkSignIn()
		},
		methods: {
			checkSignIn() {
				// 获取用户ID 检查当天是否签到
				uni.getStorage({
					key: "userInfo",
					success: (userInfo) => {
						console.log('onload', userInfo)
						this.userId = userInfo.data.id;
						this.openId = userInfo.data.wxOpenId;
						this.$request.get(this.$api.checkSignToday, {
							userId: userInfo.data.id
						}).then(signInfo => {
							// 方便调试 先都显示
							if (!signInfo.message) {
								this.showSignIn = true
							} else {
								this.showSignIn = false
							}
							// this.showSignIn = true
							uni.hideLoading()
						})
					}
				})
			},
			doSignIn() {
				const userId = this.userId
				this.$request.post(this.$api.doSign, {
					userId
				}).then(res => {
					console.log('mySignInfo', userId)
					
					// this.$request.get(this.$api.mySignInfo, {
					// 	userId
					// })
					this.$request.get(this.$api.getUserById, {
						id: userId
					}).then(result => {
						// console.log(result)
						// this.signInfo = result.result;
						this.isSign = true;
						this.integral = result.result.integral
						// uni.showToast({
						// 	icon: "success",
						// 	title: "签到成功"
						// })
						uni.hideLoading()
						uni.requestSubscribeMessage({
							// PROD: 6CRN8Jhg9wWq3WlRgMe2VppAe5La3HG_K96bBq5p0lA
							tmplIds: [this.$api.signInTempId], //数组
							success: (res) => {
								if (res[this.$api.signInTempId] === 'accept') {
									this.$request.post(this.$api.saveUserSign, {
										openId: this.openId
									}).then(result => {
										uni.showToast({
											title: "预约签到成功",
											icon: "success"
										})
										uni.hideLoading()
									})
								}
								if (res[this.$api.signInTempId] === 'reject') {
									uni.showToast({
										icon: "none",
										title: "已取消订阅"
									})
								}
							},
							fail: (err) => {
								if (err.errCode == 20004) {
									console.log('关闭小程序主开关')
								} else {
									uni.showToast({
										icon: "none",
										title: "订阅失败"
									})
								}
							}
						})
					})
				})
			},
			goSignDetail() {
				uni.navigateTo({
					url: "/pages/vIntegral/vIntegral"
				})
			}
		}
	}
</script>

<style lang="scss">
	@import "@/style/variable.scss";
	.signinPage {
		// height: calc(100vh - 100rpx);
		// overflow-y: auto;
		.signInPanel {
			height: 570rpx;
			width: 520rpx;
			position: relative;
			top: calc(40% - 285rpx);
			left: calc(50% - 260rpx);
			background-color: #fff;
			border-radius: 24rpx;
			overflow: hidden;

			.signTitle {
				width: 100%;
				height: 260rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				flex-direction: column;
				position: relative;

				.title {
					position: absolute;
					font-size: 32rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #FFFFFF;
					padding-top: 40rpx;
					bottom: 40rpx;
				}
			}

			.signInfo {
				background-color: #fff;
				display: flex;
				flex-direction: column;
				justify-content: center;
				text-align: center;
				align-items: center;
				height: 310rpx;

				.info {
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #333333;
					line-height: 50rpx;
				}
				
				.integral-text {
					font-size: $my-font-lg;
					color:  $uni-color-primary;
					font-weight: bold;
					padding: 0rpx 10rpx;
				}

				.signBtn {
					margin-top: 30rpx;
					background: linear-gradient(180deg, #87C5FC 0%, #247FFF 100%);
					box-shadow: 0px 2px 0px 1px rgba(0, 77, 161, 1);
					border-radius: 19px 19px 19px 19px;
					height: 80rpx;
					width: 400rpx;
					line-height: 80rpx;
					color: #fff;
				}
			}
		}

		.closeSignPanel {
			background: transparent;
			position: absolute;
			left: calc(50% - 35rpx);
			top: calc(40% + 380rpx);
			// bottom: 200rpx;
			// padding-bottom: 80rpx;
			// padding-bottom: calc(constant(safe-area-inset-bottom) + 80rpx);
			// padding-bottom: calc(env(safe-area-inset-bottom) + 80rpx);
		}

		.communityInfoSwiper {
			padding: 0 40rpx;
			width: calc(100% - 80rpx);
		}

		.tabAndFilter {
			display: flex;
			justify-content: flex-start;

			.tabContent {
				display: flex;
				flex-wrap: nowrap;
				justify-content: flex-start;
				padding: 0 40rpx;
				width: calc(100vw - 160rpx);
				overflow: auto;

				.tabItem {
					background: #F4F4F4;
					border-radius: 4px 4px 4px 4px;
					color: #333333FF;
					font-size: 26rpx;
					height: 62rpx;
					padding: 0 16rpx;
					line-height: 62rpx;
					margin-right: 10rpx;
					flex-shrink: 0;
				}

				.isActive {
					color: #004DA1FF;
					background-color: #E5EDFFFF;
				}
			}

			.filterContent {
				width: 80rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				position: relative;

				.filterList {
					display: flex;
					flex-wrap: wrap;
					flex-direction: column;
					position: absolute;
					background: #fff;
					top: 60rpx;
					right: 40rpx;
					width: 240rpx;
					background: #FFFFFF;
					box-shadow: 0px 3px 6px 1px rgba(0, 0, 0, 0.16);
					border-radius: 10px 10px 10px 10px;
					z-index: 9;

					.item {
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #666666;
						border-bottom: 1px solid #EEEEEEFF;
						height: 100rpx;
						line-height: 100rpx;
						padding: 0 30rpx;
						display: flex;
						flex-wrap: nowrap;
						justify-content: space-between;
						align-items: center;
					}
				}
			}
		}

		.listContent {
			display: flex;
			flex-direction: column;
			padding: 20rpx 40rpx 0;

			.list {
				display: flex;
				flex-direction: column;
				padding: 30rpx 20rpx 24rpx;
				background: #FFFFFF;
				box-shadow: inset 0px 0px 0px 1rpx rgba(230, 230, 230, .5);
				border-radius: 10px 10px 10px 10px;
				margin-bottom: 20rpx;

				.itemTop {
					display: flex;
					flex-wrap: nowrap;
					justify-content: flex-start;
					padding-bottom: 20rpx;

					.topLeft {
						display: flex;
						flex-direction: column;
						justify-content: space-between;
						width: 100%;

						.title {
							font-family: PingFang SC-Bold, PingFang SC;
							font-weight: bold;
							color: #333333;
							font-size: 28rpx;
							letter-spacing: 1rpx;
							overflow: hidden;
							text-overflow: ellipsis;
							display: -webkit-box;
							-webkit-line-clamp: 3;
							-webkit-box-orient: vertical;
							padding-right: 20rpx;
						}

						.talk {
							font-family: PingFang SC-Regular, PingFang SC;
							font-weight: 400;
							color: #004DA1;
							font-size: 26rpx;
							display: flex;
							flex-wrap: nowrap;
							overflow: auto;
							margin-right: 20rpx;

							.talkItem {
								flex-shrink: 0;
							}
						}
					}

					.topRight {
						flex-shrink: 0;
					}
				}

				.itemBottom {
					display: flex;
					flex-wrap: nowrap;
					justify-content: space-between;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #999999;
					font-size: 26rpx;

					.operate {
						display: flex;
						flex-wrap: nowrap;

						.item {
							display: flex;
							flex-wrap: nowrap;
							align-items: center;
							padding-right: 40rpx;

							.count {
								padding-left: 10rpx;
							}
						}
					}
				}
			}
		}

		.loadMoreBtn {
			padding-bottom: 40rpx;
		}
	}
</style>
